﻿using System;
using System.Collections.Generic;
using Startup.Project.Algorithm;
using Startup.Project.Classes;

namespace Startup.Shell.Domain.FunctionalityContracts
{
	public class AddCommandContract : CommandContractBase
	{
		public override string CommandName
		{
			get { return "Add"; }
		}

		public override AlgorithmAction[] GetContent(ClassBase dataContextType, StartupProperty property)
		{
			if (dataContextType == null) 
				throw new ArgumentNullException("dataContextType");
			if (!(dataContextType is CollectionStandartClass))
				throw new ArgumentException("Data context type has to be collection.", "dataContextType");
			if (property == null)
				throw new ArgumentNullException("property");

			CollectionStandartClass collectionClass = (CollectionStandartClass) dataContextType;
			List<AlgorithmAction> scenario = new List<AlgorithmAction>();
			
			CreateAction createNewItem = new CreateAction(new ConstructorDefinition(collectionClass.TemplateType));
			scenario.Add(createNewItem);

			CustomAction addAction = new CustomAction("{0}.Add({1});", property, createNewItem.Result);
			scenario.Add(addAction);

			return scenario.ToArray();
		}
	}
}
